package keepy.tech.maven.assistant;

import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class ClasspathDependencyLoader implements DependencyLoader {

    private final XmlMapper mapper = new XmlMapper();

    @Override
    public List<Dependency> loadDependencies() throws IOException {
        try (InputStream is = mapper.getClass().getClassLoader().getResourceAsStream("dependencies.xml")) {
            CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, Dependency.class);
            return mapper.readValue(is, type);
        }
    }
}
